package com.dsbridge.enrollment.jpadao;

import java.util.List;

import javax.persistence.EntityManagerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.jpa.JpaTemplate;
import org.springframework.stereotype.Repository;

import com.dsbridge.enrollment.entities.CourseAuthor;

@Repository
public class CourseAuthorJPADAO {
    
	@Autowired
	private EntityManagerFactory emf;
	
	private JpaTemplate jpaTemplate;
	
	public int createAuthor(CourseAuthor courseAuthor){
		jpaTemplate=new JpaTemplate(emf);
		jpaTemplate.persist(courseAuthor);
		return courseAuthor.getAuthorID();
	}
	
	public List<CourseAuthor> retrieveAllAuthors(){
		jpaTemplate=new JpaTemplate(emf);
		List<CourseAuthor> list=jpaTemplate.find("from com.dsbridge.enrollment.entities.CourseAuthor");
		return list;
	}
}
